package com.north.light.androidutils.photoview;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.north.light.androidutils.R;
import com.north.light.libmediapreview.PreviewManger;
import com.north.light.libmediapreview.manager.PreviewLoadPicListener;

import java.util.ArrayList;
import java.util.List;

public class MediaPreviewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_media_preview);
        ImageView img = findViewById(R.id.img);
        String url = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fgss0.baidu.com%2F7Po3dSag_xI4khGko9WTAnF6hhy%2Fzhidao%2Fpic%2Fitem%2F6a63f6246b600c33f8632fa51c4c510fd9f9a141.jpg&refer=http%3A%2F%2Fgss0.baidu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1666623672&t=c5693cca8ab7333719322358f9189178";
        String url2 = "https://img2.baidu.com/it/u=3898105799,10437040&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400";
        String url3 = "https://img2.baidu.com/it/u=3684117954,695988885&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400";
        PreviewManger.setOnPicLoadListener(loadPicListener);
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<String> urlList = new ArrayList<>();
                urlList.add(url);
                urlList.add(url2);
                urlList.add(url3);
                PreviewManger.with(MediaPreviewActivity.this)
//                        .previewOrg(1)
//                        .previewBgResId(R.color.color_000000)
                        .previewUrl(urlList)
                        .start();
            }
        });


    }

    @Override
    protected void onDestroy() {
        PreviewManger.removePicLoadListener(loadPicListener);
        super.onDestroy();
    }

    private PreviewLoadPicListener loadPicListener = new PreviewLoadPicListener() {
        @Override
        public <T extends ImageView> void loadPic(String url, T t) {
            Glide.with(MediaPreviewActivity.this)
                    .load(url)
                    .into(t);
        }
    };
}